package module3;

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class MyJTabbedPane extends JPanel implements ActionListener
{
	//attributes
	private int count;
	private JPanel pOne = null,pTwo = null,pThree = null;
	private JPanel picPanel = null,picPanel2 = null,buttonPanel = null;
	private JScrollPane scrollPane = null,scrollPane2 = null;
	private JLabel picLabel = null,picLabel2 = null;
	private JButton pOneBut = null,pTwoBut = null,pThreeBut = null;
	private JButton firstB = null,lastB = null,nextB = null,previousB = null;
	private ImageIcon ii = null,ii2 = null;
	private JTabbedPane tab = null;
	
	//constructor
	public MyJTabbedPane()
	{
		count = 1;
		pOne = new JPanel();
		pOne.setBackground(Color.red);
		pOneBut = new JButton(new ImageIcon("c:\\javausers\\IconImages\\door_exit1.gif"));
	//	pOneBut.add());
		pOneBut.addActionListener(this);
		pOne.add(pOneBut);
		pTwo = new JPanel(new BorderLayout());
		pTwo.setBackground(Color.yellow);
		pTwoBut = new JButton("BUTTON2");
		pTwo.add(pTwoBut);
		pThree = new JPanel();
		pThree.setBackground(Color.black);
		pThreeBut = new JButton("BUTTON3");
		pThree.add(pThreeBut);
		ii = new ImageIcon("c:\\javausers\\IconImages\\cross1.gif");
		ii2 = new ImageIcon("c:\\javausers\\IconImages\\earth16.gif");
		
		//setup center area of pTwo
		picLabel = new JLabel(new ImageIcon("c:\\javausers\\Misc\\Cape"+count+".jpg"));
		//picLabel2 = new JLabel(new ImageIcon("c:\\javausers\\Misc\\Cape2.jpg"));
		scrollPane = new JScrollPane(picLabel,JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
		picPanel = new JPanel(new GridLayout(1,1));	
		picPanel.add(scrollPane);
		pTwo.add(picPanel,BorderLayout.CENTER);	
		
		tab = new JTabbedPane();
	    tab.addTab("Panel1",ii,pOne);
	    tab.addTab("Panel2",ii2,pTwo);
	    tab.add("Panel3",pThree);
		
		//setup "this" jPanel
		this.setLayout(new GridLayout(1,1));
		this.add(tab);
		
		//setup button panel
		firstB = new JButton(new ImageIcon("c:\\javausers\\IconImages\\arrowUp1.gif"));
		firstB.addActionListener(this);
		firstB.setToolTipText("goTO first PIC");
		lastB = new JButton(new ImageIcon("c:\\javausers\\IconImages\\arrowDown2.gif"));
		lastB.addActionListener(this);
		lastB.setToolTipText("goTO last PIC");
		nextB = new JButton(new ImageIcon("c:\\javausers\\IconImages\\rightArrowClear.gif"));
		nextB.addActionListener(this);
		nextB.setToolTipText("NEXT IMAGE");
		previousB = new JButton(new ImageIcon("c:\\javausers\\IconImages\\leftArrowClear.gif"));
		previousB.addActionListener(this);
		previousB.setToolTipText("PREVIOUS IMAGE");
		buttonPanel = new JPanel();
		buttonPanel.add(previousB);
		buttonPanel.add(firstB);
		buttonPanel.add(lastB);
		buttonPanel.add(nextB);
		pTwo.add(buttonPanel,BorderLayout.SOUTH);
		
		
	}//end constructor
	
	public void actionPerformed(ActionEvent e)
	{
		Object source = e.getSource();
		if(source == pOneBut)
		{
			tab.setSelectedIndex(2);
		}//
		if(source == firstB)
		{
			count = 1;
			this.setPicture();
		}//
		if(source == lastB)
		{
			count = 9;
			this.setPicture();
		}//
		if(source == nextB)
		{
			count++;
			if(count == 10)
			{
				count = 1;
			}
			this.setPicture();
		}//
		if(source == previousB)
		{
			count--;
			if(count == 0)
			{
				count = 9;
			}
			this.setPicture();
		}//
		
	}
	//method because repetitive code was noticed
	private void setPicture()
	{
		String fileName;
		fileName = "c:\\javausers\\Misc\\Cape"+count+".jpg";
		ii = new ImageIcon(fileName);
		picLabel.setIcon(ii);
		scrollPane.validate();
	}
	
}//end public class